package com.qs.service.impl;

import com.qs.mapper.*;
import com.qs.model.entity.*;
import com.qs.service.IAsyncService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
 * ClassName: AsyncServiceImpl
 * Package: com.qs.service
 * Description:
 *
 * @Author: @weixueshi
 * @Create: 2024/3/30 - 15:18
 * @Version: v1.0
 */
@Slf4j
@Service
@Async("asyncExecutor")
@RequiredArgsConstructor
public class AsyncServiceImpl  implements IAsyncService {

    private final OrderInfoMapper orderInfoMapper;
    private final OrderItemMapper orderItemMapper;
    private final PayInfoMapper payInfoMapper;
    private final CartMapper cartMapper;
    private final UserGoodsLogMapper userGoodsLogMapper;
    private final GoodsMapper goodsMapper;

    @Override
    public void saveOrderInfo(OrderInfo orderInfo) {
        orderInfoMapper.insert(orderInfo);
        log.info("保存订单信息成功：qs_order_info");
    }

    @Override
    public void saveOrderItem(OrderItem orderItem) {
        orderItemMapper.insert(orderItem);
        log.info("保存订单信息成功：qs_order_item");
    }

    @Override
    public void savePayInfo(PayInfo payInfo) {
        payInfoMapper.insert(payInfo);
        log.info("保存订单信息成功：qs_pay_info");
    }

    @Override
    public void deleteCart(Integer cartId) {
        cartMapper.deleteById(cartId);
        log.info("删除id为{}的购物车数据成功",cartId);
    }

    @Override
    public void saveUserGoodsLog(UserGoodsLog userGoodsLog) {
        userGoodsLogMapper.insert(userGoodsLog);
        log.info("保存订单信息成功：qs_user_goods_log");
    }

    @Override
    public void incrementViewCount(Integer id) {
        Goods goods = goodsMapper.selectById(id);
        goods.setBrowse(goods.getBrowse() + 1);
        goodsMapper.updateById(goods);
    }
}
